package com.atchangsha.system.service.impl;

import com.atchangsha.system.common.utils.Result;
import com.atchangsha.system.constant.SalesBillConstants;
import com.atchangsha.system.dto.SalesBillDTO;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atchangsha.system.common.utils.PageUtils;
import com.atchangsha.system.common.utils.Query;
import com.atchangsha.system.dao.SalesBillDao;
import com.atchangsha.system.entity.SalesBillEntity;
import com.atchangsha.system.service.SalesBillService;

@Service("salesBillService")
public class SalesBillServiceImpl extends ServiceImpl<SalesBillDao, SalesBillEntity> implements SalesBillService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SalesBillEntity> page = this.page(
                new Query<SalesBillEntity>().getPage(params),
                new QueryWrapper<SalesBillEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public Result add(SalesBillDTO salesBillDTO) {
        SalesBillEntity entity = salesBillDTO.toEntity();
        int insert = baseMapper.insert(entity);
        if (insert == 1){
            return Result.ok(SalesBillConstants.SalesBillEnum.ADD_SUCCESS).setResult(entity.toEntity());
        }
        return Result.fail(SalesBillConstants.SalesBillEnum.ADD_FAIL);
    }

}